package main

import (
	"encoding/json"
	"net/http"
)

type User struct {
	Id    int
	Name  string
	Age   int
	hobby string
}

func myHandle(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")
	user := &User{
		Id:    1,
		Name:  "kevin",
		Age:   18,
		hobby: "code",
	}
	u, _ := json.Marshal(user)
	w.Write(u)
}

func myHandleRedirct(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Location", "https://www.baidu.com")
	w.WriteHeader(302)
}
func main() {
	http.HandleFunc("/testResponse", myHandle)
	http.HandleFunc("/testRedirect", myHandleRedirct)
	http.ListenAndServe(":8088", nil)

}
